package com.bruce.listener;

import com.bruce.config.QuartzConfig;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * 创建一个监听器,在sping容器启动的时候自动调用
 */
@Configuration
public class QuartzJobListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private QuartzConfig quartzConfig;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        System.out.println("web项目已经启动");
        quartzConfig.startJob();
        System.out.println("任务已经启动...");
    }
}
